package cn.imnaer.service.rest.view.model;


import java.util.ArrayList;
import java.util.List;

import cn.imnaer.common.factory.JacksonUtil;

public class Response extends SimpleResponse{
	public int totalCount;
	public int pageCount=1;
	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}
	public String success(List<?> record) {
		this.setCode(ERROR_NONE);
		if (record == null || record.size() == 0) {
			record = new ArrayList<>(1);
			this.setCode(DATA_EMPTY);
			this.setTotalCount(0);
		}
		else{
			this.setTotalCount(record.size());
		}
		this.setRecord(record);
		this.setType(this.TYPE_ARRAY);
		return JacksonUtil.beanToJson(this);
	}
	public String success(Object[] record) {
		this.setCode(ERROR_NONE);
		if (record == null || record.length == 0) {
			record = new Object[1];
			this.setCode(DATA_EMPTY);
			this.setTotalCount(0);
		}
		else{
			this.setTotalCount(record.length);
		}
		this.setRecord(record);	
		this.setType(this.TYPE_ARRAY);
		return JacksonUtil.beanToJson(this);
	}
	public String success(List<?> record, int pageCount) {
		this.success(record);
		this.setPageCount(pageCount);
		return JacksonUtil.beanToJson(this);
	}
}
